<%@ page language="java" pageEncoding="UTF-8"%>
<div class="modal-body">
  <form id="user-form" name="user-form" class="form-horizontal">
		<input type="hidden" name="id" id="knowledgeId">
		<input type="hidden" name="createTime" data-flag="date" data-format="yyyy-MM-dd HH:mm:ss">
		<input type="hidden" name="deleted">
		<div class="box-body">
			<div class="col-md-12">
				<div class="form-group">
					<label for="title" class="col-sm-1 control-label">标题</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" id="title" name="title" placeholder="标题">
					</div>
				</div>
				<div class="form-group">
					<label for="type" class="col-sm-1 control-label">类别</label>
					<div class="col-sm-6">
						<select id="type" class="form-control" name="type">
								<option value="经验规则" label="经验规则">经验规则</option>
								<option value="决策模型" label="决策模型">决策模型</option>
								<option value="历史案例" label="历史案例">历史案例</option>
								<option value="应急预案" label="应急预案">应急预案</option>
								<option value="决策方案" label="决策方案">决策方案</option>
						</select>
					</div>
				</div>
			</div>
		</div>
	</form>
  <script id="container" name="content" type="text/plain" style="margin-top:100px; margin-bottom:10px"></script>
  <div class="box-footer text-right">
	<!--以下两种方式提交验证,根据所需选择-->
	<button type="button" class="btn btn-default" data-btn-type="cancel" onclick="dialog_close()">取消</button>
	<button type="button" class="btn btn-primary" data-btn-type="save" onclick="saveHtml()">提交</button>
</div>
</div>
<!-- baidu ueditor-->
<script src="${pageContext.request.contextPath}/ueditor/ueditor.config.js"></script>
<script src="${pageContext.request.contextPath}/ueditor/ueditor.all.js"></script>
<script src="${pageContext.request.contextPath}/ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
  UE.delEditor('container');
  var editor = UE.getEditor('container');
  var id = "";
  editor.addListener("ready", function () {
	editor.setHeight(350);
    // editor准备好之后才可以使用
    if( Dtable_knowledge.rows('.selected').data()[0] ){
    	id = Dtable_knowledge.rows('.selected').data()[0].id;
    	
    	if( id != null && id != ""){
    		var url = "../../tbl_knowledge_base/" + id;		
        	$.ajax({
      		  url: url,
      		  type : 'get',
      		  async : false,
      		  contentType: "application/json; charset=utf-8",
      		  dataType: "json",
      		  success: function(json) {
      			  console.log(json);
      			  $("#title").val( json.data.title );
      			  $("#type").val( json.data.type );
      			  editor.setContent(json.data.html);
      		  }
      		});
        }
    }else{
    	editor.setContent("请输入内容");
    }
  });

  function saveHtml( fn ) {
		var url = "../../tbl_knowledge_base/save";		
		var knowledge = {};
		knowledge.title = $("#title").val();
		knowledge.type = $("#type").val();
		knowledge.html = editor.getContent();
		knowledge.id = id;
		var json_data = JSON.stringify( knowledge );
		$.ajax({
			  url: url,
			  type : 'post',
			  async : false,
			  data: json_data,
			  contentType: "application/json; charset=utf-8",
			  dataType: "json",
			  success: function(json) {
				 global.alert( json.message );
				 $("#knowledge_main").load("knowledge/knowledge_list.html");
				 dialog_close();
			  }
		});
  }
  
  function dialog_close(){
		global.dialog.close()
	}
</script>
</html>
